import config from './config'
import _ from 'lodash'

/**
 * 模块定制
 * 
 * @param {any} data 
 * @returns 
 */
const getModule = function (type) {
    return config.http('GET_HEAD_MENU').then(data => {
        const mkstr = localStorage.mk;
        var mk = [];
        if (mkstr) {
            mk = mkstr.split(',');
        }
        const originList = _.clone(data);
        let fixedList = _.filter(data, item => {
            return item.forbidChange
        })
        let select = _.filter(data, item => {
            return mk.indexOf(item.route) > -1
        })
        select = _.sortBy(select ,item =>{
            return mk.indexOf(item.route)
        })
        _.remove(data, item => {
            return item.forbidChange
        })
        let changeList = data;
        let data1 = _.clone(data);
        _.remove(data1, item => {
            return mk.indexOf(item.route) > -1
        })
        let unselect = data1;
        let all = select.concat(fixedList)
        if (type == 'all') {
            console.log(mkstr)
            if (!mkstr || mkstr == 'null') {
                console.log(originList)
                return originList
            } else {
                return all
            }
        } else if (type == 'unselect') {
            if (!mkstr || mkstr == 'null') {
                return []
            } else {
                return unselect
            }
        } else if (type == 'select') {
            if (!mkstr || mkstr == 'null') {
                return changeList
            } else {
                return select
            }
        }
    })
}

export {
    getModule
}
